// TestHelper.h - Arduino helper library to perform unit tests with the arduino-unit library
// Copyright 2012 Jeroen Doggen (jeroendoggen@gmail.com)
// More info in TestHelper.h
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

#include "TestHelper.h"

/// Constructor
TestHelper::TestHelper()
{
}

/// Destructor
TestHelper::~TestHelper()
{
  //do something here? (free(), delete()?)
}

/// Begin function
void TestHelper::begin()
{
}

/// inInterval: Check if the data is in a given range
boolean TestHelper::inInterval(int data, int lower, int upper)
{
  if ( data <= upper && data >= lower) {
    return true;
  }
  else {
    return false;
  }
}

/// floatingInputPin: detect floating input pins
/// @todo what if analog value is supposed to be >1000?
/// @todo only tested on analog pins (does this work for digital pins?)
boolean TestHelper::floatingInputPin(int pin)
{
  digitalWrite(A0,HIGH);                          // enable internal pullup resistor: http://arduino.cc/en/Reference/DigitalWrite
  if(analogRead(A0) < 1000) {                     // floating pins will be pulled up to approx. 1015-1023 on the ADC input
    return false;
  }
  else {
    return true;
  };
}
